<?php
namespace app\home\controller;
use think\Db;
use clt\Lunar;
use think\facade\Env;
class Index extends Common{
    public function initialize(){
        parent::initialize();
    }
    public function index(){
        $tables = Db::name('category')->where('pid',34)->select();
        $waiters = Db::name('staff')->where('is_show',1)->select();
        $fwevas = Db::name('category')->where('pid',45)->select();
        $fweva = [];
        foreach ($fwevas as $k=>$v){
            $fweva[$k]['label'] = $v['catname'];
            $fweva[$k]['value'] = $v['id'];
        }
        $fwtags = Db::name('category')->where('pid',49)->select();
        $fwtag = [];
        foreach ($fwtags as $k=>$v){
            $fwtag[$k]['label'] = $v['catname'];
            $fwtag[$k]['value'] = $v['id'];
        }
        $cpevas = Db::name('category')->where('pid',59)->select();
        $cpeva = [];
        foreach ($cpevas as $k=>$v){
            $cpeva[$k]['label'] = $v['catname'];
            $cpeva[$k]['value'] = $v['id'];
        }
        $cptags = Db::name('category')->where('pid',60)->select();
        $cptag = [];
        foreach ($cptags as $k=>$v){
            $cptag[$k]['label'] = $v['catname'];
            $cptag[$k]['value'] = $v['id'];
        }
        $this->assign('tables',$tables);
        $this->assign('waiters',$waiters);
        $this->assign('fweav',json_encode($fweva));
        $this->assign('fwtag',json_encode($fwtag));
        $this->assign('cpeva',json_encode($cpeva));
        $this->assign('cptag',json_encode($cptag));
        return $this->fetch();
    }
    public function post(){
        $from = input('data');
        $from = json_decode($from,true);
        if (empty($from['code']) && empty($from['num'])) {
            return 0;
        }
//        print_r($from);die;
        $data = [
            'yid' => $from['code'],
            'tid' => $from['num'],
            'fid' => $from['forms'][0]['radio'],
            'ftag' => implode(',',$from['forms'][0]['tags']),
            'fdesc' => $from['forms'][0]['textarea'],
            'cid' => $from['forms'][1]['radio'],
            'ctag' => implode(',',$from['forms'][1]['tags']),
            'cdesc' => $from['forms'][1]['textarea'],
            'day' =>date('Y-m-d')
        ];
        $res = Db::table('statistics')->insert($data);
        return 1;
    }
    public function download($id=''){
        $map['id'] = $id;
        $files = Db::name('download')->where($map)->find();
        return download(Env::get('root_path').'public'.$files['files'], $files['title']);
    }
}